﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using Tank.Resources;

namespace Tank.Draw
{
    public class Map
    {
        //private static Image wallImages = Image.FromFile(Directory.GetCurrentDirectory() + @"\Image\wall.gif");
        //private static Image steelImages = Image.FromFile(Directory.GetCurrentDirectory() + @"\Image\steel.gif");
        //private static Image grassImages = Image.FromFile(Directory.GetCurrentDirectory() + @"\Image\grass.png");
        //private static Image waterImages = Image.FromFile(Directory.GetCurrentDirectory() + @"\Image\water.gif");

        //private static Image wallImage = Image.FromFile(Directory.GetCurrentDirectory() + @"\Image\wall.gif").GetThumbnailImage(Data.GridSize, Data.GridSize, () => { return false; }, IntPtr.Zero);
        //private static Image steelImage = Image.FromFile(Directory.GetCurrentDirectory() + @"\Image\steel.gif").GetThumbnailImage(Data.GridSize, Data.GridSize, () => { return false; }, IntPtr.Zero);
        //private static Image grassImage = Image.FromFile(Directory.GetCurrentDirectory() + @"\Image\grass.png").GetThumbnailImage(Data.GridSize, Data.GridSize, () => { return false; }, IntPtr.Zero);
        //private static Image waterImage = Image.FromFile(Directory.GetCurrentDirectory() + @"\Image\water.gif").GetThumbnailImage(Data.GridSize, Data.GridSize, () => { return false; }, IntPtr.Zero);

        /// <summary>
        /// 当前关卡
        /// </summary>
        public static int index = 0;

        /// <summary>
        /// 地图元素集合
        /// </summary>
        public static Dictionary<Point, Data.mapImage> mapDic = new Dictionary<Point, Data.mapImage>();

        /// <summary>
        /// 获取地图
        /// </summary>
        /// <returns></returns>
        public static Image getMapImage()
        {
            Image image = new Bitmap(26 * Data.GridSize, 26 * Data.GridSize);
            Graphics g = Graphics.FromImage(image);
            g.Clear(Color.Black);
            foreach (var item in mapDic)
            {
                switch (item.Value)
                {
                    case Data.mapImage.wall:
                        g.DrawImage(ImageResources.wallImage, item.Key);
                        break;
                    case Data.mapImage.steel:
                        g.DrawImage(ImageResources.steelImage, item.Key);
                        break;
                    case Data.mapImage.grass:
                        g.DrawImage(ImageResources.grassImage, item.Key);
                        break;
                    case Data.mapImage.water:
                        g.DrawImage(ImageResources.waterImage, item.Key);
                        break;
                }
            }
            return image;
        }

        /// <summary>
        /// 设置地图
        /// </summary>
        /// <param name="map"></param>
        public static void setMap(Dictionary<Point, Data.mapImage> map, int i)
        {
            mapDic = map;
            index = i;
        }
    }
}
